package com.wlx.file.service;

import com.wlx.file.utils.AliyunOssService;
import com.wlx.file.utils.FileUploadUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

/**
 * Minio 文件存储
 *
 * @author wlx
 */
@Service
public class AliOssSysFileServiceImpl implements ISysFileService {
    @Autowired
    private AliyunOssService aliyunOssService;

    /**
     * 本地文件上传接口
     *
     * @param file 上传的文件
     * @return 访问地址
     * @throws Exception
     */
    @Override
    public String uploadFile(MultipartFile file) throws Exception {
        String extractFilename = FileUploadUtils.extractFilename(file);
        boolean upload = aliyunOssService.upload(extractFilename, file.getBytes());
        if (upload) {
            return aliyunOssService.downloadUrl(extractFilename);
        }
        return null;
    }
}
